package com.itheima.dao;

import com.itheima.pojo.Account;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class AccountDaoTest2 {

    private AccountDao accountDao;

    @Before
    public void before() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        accountDao = context.getBean(AccountDao.class);
    }

    @Test
    public void add() {
        Account account = new Account();
        account.setMoney(888888);
        account.setName("刘强东");
        accountDao.add(account);
        System.out.println("id:" + account.getId());
        System.out.println(accountDao.findById(account.getId()));
    }

    @Test
    public void update() {
        Account account = new Account(6, "刘强东", 66666666);
        accountDao.update(account);
        System.out.println(accountDao.findById(6));
    }

    @Test
    public void findById() {
        System.out.println(accountDao.findById(6));
    }

    @Test
    public void delete() {
        accountDao.delete(6);
        System.out.println(accountDao.findById(6));
    }

    @Test
    public void findAll() {
        List<Account> accounts = accountDao.findAll();
        accounts.forEach(account -> System.out.println(account));
    }
}
